<?php
session_start();
require_once( 'group_db.php' );
 
$type = new M_Group();
$user_id = $_SESSION['userid'];

if (isset($_POST['m'])  &&  $_POST['m']!=""){
    if ($_POST['m']== 'load'){

      $result=$type->loadData();
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['id'],$row['name'], $row['status']) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);

    }else if ($_POST['m']=='add'){
        $ar = array();
		$ar['name']=  $_POST['name'];
		$ar['status'] = $_POST['status'];
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		  
		$id=$type->InsertData($ar);
		
		$val = $_POST['list'];
		
		if (count($val)> 0){
			foreach($val as $row){
				$row['gid'] = $id;
				$type->InsertPermission($row);
			}
		}
		
    }else if ($_POST['m']=='edit'){
		$ar = array();
		$gid = $_POST['id'];
		$ar['name']=  $_POST['name'];
		$ar['status'] = $_POST['status'];
		$ar['createdate'] =date( "Y/m/d H:i:s" );
		$ar['createby'] = $user_id;
		  
		$type->UpdateData($gid,$ar);
		$type->DeletePermission($gid);
		
		$val = $_POST['list'];
		
		if (count($val)> 0){
			foreach($val as $row){
				$row['gid'] = $gid;
				$type->InsertPermission($row);
			}
		}
		// echo json_encode($strcipt);
	}
	else if ($_POST['m']=='del'){
         $id=$_POST['id'];
 
		 $type->deleData($id);
		 
    }/// Age Criteria
  
	  
	else if ($_POST['m'] =='load_detail'){
	  $id=$_POST['id'];
	  $t=$_POST['type'];
	  $result=$type->loadPermissionScreen($id,$t);
      $rows=$type->getRowCount();
      $i=1;
      $html="";
      if ($rows>0){
           $data = array();
            while($row = $result->FetchRow()){
               $data[] = array(0,$row['id'], $row['name'],$row['v'], $row['a'], $row['e'],$row['d'],$row['col1'],$row['isView'],$row['isAdd'], $row['isEdit'], $row['isDel'],$row['isCol1'] ) ;
            }
        }else{
			$data = array();
        }
    
        $arr = array('aaData'=>$data);
        
        echo json_encode($arr);
	
	}
}else{
}
 
?>